/**
 * inforcreation.com co.Ltd
 * MichaelHuang
 * 2011-12-17
 */
package com.zchat.api.connection;

import android.content.Context;
import android.util.Log;

import com.zchat.android.BootActivity;
import com.zchat.api.log.Logger;
import com.zchat.api.util.ZChatSetting;

/**
 * User can get current net type from this class.
 * @author MichaelHuang
 *
 */
public class NetUtil {
	String TAG = "NetUtils";

	private NetUtil() {
		
	}
	private static NetUtil instance = new NetUtil();
	public static NetUtil getInstance() {
		return instance;
	}
	private NetType netType;		//net type
	private NetStatus netStatus;	//net status
	public void setNetType(NetType netType) {
		if(ZChatSetting.DEBUG) Logger.info(TAG+"-Current net type is : " + netType.toString());
//		Logger.debug("Current net type is : " + netType.toString());
		this.netType = netType;
	}
	
	/**
	 * 根据连接上的网络 去监测与应用服务器的连接状态
	 * @param context
	 * @param netStatus
	 */
	public void setNetStatus(final Context context, NetStatus netStatus) {
		if(ZChatSetting.DEBUG) Logger.info(TAG+"-设置网络状态为：" + netStatus);
		this.netStatus = netStatus;
		if(this.netStatus == NetStatus.avaliable) {
			//检测可用网络
			new Thread() {
				public void run() {
					AppNet.detectLinkedNet(context);
					BootActivity.setDetected(true);
				}
			}.start();
		} else if(this.netStatus == NetStatus.unavaliable) {
			//网络状态不可用时，直接设置为离线阅读
			ReadStatusUtil.getInstance().setStatus(context, ReadStatus.offline);
		}
	}
	
	public NetType getCurrentNetType() {
		return this.netType;
	}
}
